package com.codefish.framework.spring.aop.support;

import com.codefish.framework.spring.aop.framework.AdviseSupport;
import com.codefish.framework.spring.core.utils.ReflectionUtils;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/10/15 上午 09:44
 */
public abstract class AopUtils {
    public static boolean isEqualsMethod(Method method) {
        return ReflectionUtils.isEqualsMethod(method);
    }

    public static boolean isHashCodeMethod(Method method) {
        return ReflectionUtils.isHashCodeMethod(method);
    }

    public static boolean equalInProxy(AdviseSupport a, AdviseSupport b) {
        return (a == b) || (a.getTargetResource().equals(b.getTargetResource()) && hasSameInterfaces(a, b));
    }

    private static boolean hasSameInterfaces(AdviseSupport a, AdviseSupport b) {
        if (a == null) {
            return b == null;
        }
        return Arrays.equals(a.getInterfaces(), b.getInterfaces());
    }
}
